<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<title>商品订单管理</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="${s.base}/js/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="${s.base}/css/base/base.css" media="all" /></head>

<body class="childrenBody">
<form class="layui-form">
	<blockquote class="layui-elem-quote quoteBox" id="tool">
		<div class="layui-inline">
			<label class="layui-input-inline">姓名</label>
			<label class="layui-input-inline">
				<input type="text" class="layui-input" name="memberName" placeholder="请输入姓名" />
			</label>
			<label class="layui-input-inline">手机号</label>
			<label class="layui-input-inline">
				<input type="text" class="layui-input" name="memberPhone" placeholder="请输入手机号" />
			</label>

			<a class="layui-btn search_btn" lay-submit="" lay-filter="seacherBtn">搜索</a>
			<a class="layui-btn layui-btn-normal countMoneyBtn" >付现</a>
			<a class="layui-btn export_btn" lay-submit="" >导出</a>
		</div>
	</blockquote>
	<table id="entityList" lay-filter="entityList"></table>
</form>

<script type="text/javascript" src="${s.base}/js/layui/layui.js"></script>
<script type="text/javascript" src="${s.base}/js/base/base.js"></script>
<script type="text/javascript">layui.use(['jquery', 'pageUtil', 'dialogUtil', 'table', 'dateUtil'],
    function() {
        var $ = layui.jquery,
            dateUtil = layui.dateUtil,
            dialogUtil = layui.dialogUtil,
            table = layui.table,
            pageUtil = layui.pageUtil;
        var tableIns = null;
        var orderId = '${orderId}';
        pageUtil.initDict("shop_order_cash_status",
            function(dictData) {
                // pageUtil.showDict($("#status"), pageUtil.aceeptDictContentList(dictData, "shop_order_cash_status"), "请选择状态");
                var url = "/shopOrderCoupon/pageShowOrder?orderId="+orderId;
                var cols = [{
                    type: 'checkbox',
                    fixed: 'left'
                },
                    {
                        type: 'numbers',
                        title: '序号'
                    },
                    {
                        field: 'memberName',
                        title: '姓名',
                        align: 'center'
                    },
                    {
                        field: 'memberPhone',
                        title: '手机号',
                        align: 'center'
                    },
                    {
                        field: 'alipay',
                        title: '支付宝',
                        align: 'center'
                    },
                    {
                        field: 'bankCard',
                        title: '银行',
                        align: 'center'
                    },
                    {
                        field: 'money',
                        title: '金额',
                        align: 'center'
                    },
					{field: 'cashStatus', title: '状态',align:'center', templet:function(d){
                            return pageUtil.aceeptDictContentName(dictData,"shop_order_cash_status",d.cashStatus);
                        }},
                    {
                        field: 'cashMessage',
                        title: '付现原因',
                        align: 'center'
                    },
                    {
                        field: 'cashTime',
                        title: '付现时间',
                        width: 190,
                        align: 'center',
                        templet: function(d) {
                            if (d.cashTime != null) {
                                return dateUtil.formatDate(new Date(d.cashTime), "yyyy-MM-dd HH:mm:ss");
							} else{
                                return "";
							}
                        }
                    }];
                tableIns = pageUtil.initDate(cols, url, true);
            });

        // 打款通知
        $(".countMoneyBtn").click(function(){
            // 获取所有的ids
            var checkStatus = layui.table.checkStatus('entityList').data;

            if(checkStatus.length == 0){
                layer.alert("请选择至少一个用户订单！")
                return false;
            }
            var cashStatusFlag = true;
            var memberIds = [];
            $.each(checkStatus,function(i,v){
                // 已提现的无法操作
                if (v.cashStatus == "2") {
                    cashStatusFlag = false;
                }
                memberIds.push(v.memberId);
            });
            if (!cashStatusFlag) {
                layer.alert("您只能选择未提现的用户操作！")
                return false;
            }
            var memberIdsStr = memberIds.join(",");
            //console.log(ids.join(","));
            // 打款，并记录
            var index = layer.open({
                type: 1,
                title:'付现',
                area: ['400px', 'auto'], //宽高
                btn:['确定','取消'],
                content: '<div style="height: 195px;padding: 15px !important;">'+
                '<form class="layui-form" action="">'+
                '<div class="layui-form-item layui-form-text" >'+
                '<div class="layui-input-line">'+
                '<select class="form-control" name="cashStatus" lay-verify="required" id="cashStatus"></select>'+
                '</div>'+
                '</div>'+
                '<div class="layui-form-item layui-form-text" >'+
                ' <textarea id="cashMessage" style="width:369px;height: 135px;!important;">已通过银行打款，请查收</textarea>'+
                '</div>'+
                '</form>'+
                '</div>'
                ,success:function(){
                    pageUtil.initDict("shop_order_cash_status",
                        function(dictData) {
                            pageUtil.showDict($("#cashStatus"), pageUtil.aceeptDictContentList(dictData, "shop_order_cash_status"), "", "");
                        });
                }
                ,yes:function (){
                    var cashMessage = $("#cashMessage").val();
                    var cashStatus = $("#cashStatus").val();
                    if(cashMessage == null || cashMessage == ""){
                        dialogUtil.alert("请填写付现原因");
                        return false;
                    }
                    if(cashMessage.length > 200){
                        dialogUtil.alert("纠纷原因不能超过100个字");
                        return false;
                    }
                    var params={
                        "orderId":orderId,
                        "memberIds":memberIdsStr,
                        "cashStatus":cashStatus,
                        "cashMessage":cashMessage
                    }
                    $.post("/shopOrderCoupon/updateCashStatus", params, function (result) {
                        layer.close(index);
                        if (result.code === 0) {
                            //操作成功
                            tableIns.reload();
                        } else {
                            //操作失败
                            dialogUtil.alert(result.msg);
                        }
                    }, "json");
                }
                ,btn2: function(index, layero){

                }
            });
        });

        // 导出
		$(".export_btn").on("click",function(){
			window.location.href = "/shopOrder/export?orderId="+orderId;
		});

        table.on('tool(entityList)',
            function(obj) {
                var layEvent = obj.event,
                    data = obj.data;
                if (layEvent === 'del') {
                    pageUtil.delete("确定删除该项吗？", "/shopOrder/delete", {
                            "id": data.id,
                            "_method": "DELETE"
                        },
                        function(data) {
                            tableIns.reload();
                        });
                }
            });
    })</script>
</body>

</html>